/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/18
 * Time:19:21
 */
public class Solution {
    public ListNode reverseList(ListNode head) {
        if(head == null) return null;
        if(head.next == null) return head;
        ListNode pre = new ListNode(-1);
        ListNode index = pre;
        ListNode cur = head;
        pre.next = cur;
        while (cur.next != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        cur.next = pre;
        index.next = null;
        head.next = null;
        return cur;
    }
}
